package com.hdoit.kylin.web.money.providers;

import java.util.ArrayList;
import java.util.List;
import com.hdoit.kylin.logical.group.model.Project;
import com.hdoit.kylin.logical.group.service.IProjectService;
import com.hdoit.kylin.web.common.CommonWebUtils;
import com.tennetcn.common.aop.CommonApplicationContextUtil;
import com.tennetcn.common.message.ListItem;
import com.tennetcn.common.message.LoginModel;
import com.tennetcn.component.attribute.provider.ISingleOptionListProvider;
import com.tennetcn.component.web.SessionWebFactory;
import com.tennetcn.web.cbase.providers.base.DataListProviderBase;

/** 
 * @author      chenghuan
 * @email       79763939@qq.com
 * @createtime  2017年5月17日 上午9:17:39
 * @comment 
 */
public class ProjectOwnProvider extends  DataListProviderBase implements ISingleOptionListProvider<ListItem>{
	
	
	@Override
	public List<ListItem> getDataList(Object viewData) {
		List<Project> projects= getOwnProjectList();
		if(projects==null||projects.size()<=0){
			return null;
		}
		dataList=new ArrayList<ListItem>();
		ListItem listItem=null;
		for (Project project : projects) {
			listItem=new ListItem();
			listItem.setText(project.getProjectName());
			listItem.setValue(project.getProjectId());
			dataList.add(listItem);
		}
		return dataList;
	}

	private List<Project> getOwnProjectList(){
		SessionWebFactory sessionWebFactory=CommonApplicationContextUtil.getCurrentContext().getBean(SessionWebFactory.class);
		IProjectService projectService=CommonApplicationContextUtil.getCurrentContext().getBean(IProjectService.class);
		LoginModel loginModel=sessionWebFactory.getCurrentLogin();
		String loginId=loginModel.getLoginId();
		if(CommonWebUtils.isTeacher(loginModel)||CommonWebUtils.isStudent(loginModel))
			return projectService.queryListByOwn(loginId); 
		else
			return projectService.queryList();
	}

}
